/*
 ============================================================================
 Name        : stdin2socket.cpp
 Author      : linchen
 Version     :
 Copyright   : Zhejiang Chuangyi Technology Co., Ltd.
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <iostream>
#include <sstream>
#include "tcpServer.h"

int main(void)
{

	daemon(1, 1);

	std::string msgbuf;
	signal(SIGPIPE, SIG_IGN);
	TcpServer tcpServer(54321);
	tcpServer.start();
	unsigned char c;

	while(1)
	{
		c = getchar();
		if((c == EOF) || (c == 0xFF))
			break;
		msgbuf += c;
		printf("%c", c);

		if(c == 0x0A) // 换行再输出 提高效率
		{
			tcpServer.sendBroadcastMessage(msgbuf.c_str(), msgbuf.length());
			msgbuf.clear();
		}
	}

	return EXIT_SUCCESS;
}
